<script type="text/javascript">	
	function delete_Affiliate(id){
		var $dialog = $(
					"<div title='Delete'>"+
					"<p style='margin-top:40px; font-family:arial; margin-left:35px;'>Are you sure you want to delete this?</p>"+
					"</div>"
				);
		$dialog.dialog({
			autoOpen: false,
			modal: true,
			zIndex:9999,
			buttons:{
				"Yes": function(){
					$.post("query/delete_affiliate.php", {affiliate_id: id}, function(data){
						window.location.replace("panel.php?page=affiliate");
					});
					$( this ).dialog("close");
				},
				"NO": function(){
					$( this ).dialog("close");
				}
			}
		});
		$dialog.dialog("open");
		return false;
	}
</script>
<?php 
	include("query/db_connection.php");	
	$acc_num = 0;
?>
<!--  start nav-outer-repeat................................................... END -->
<div class="clear"></div>
<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->
<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Affiliate</h1>
	</div>
	<!-- end page-heading -->
<?php if($admin=="yes"){ ?>	
	<div id="affiliate_submenus">
			<a  href="panel.php?page=add_affiliate"><img style="border:none;" alt="add affiliate" src="images/forms/add_affiliate.gif" /></a>
	</div>
<?php } ?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
		
			<!--  start table-content  -->
			<div id="table-content">	
				<!--  start product-table ..................................................................................... -->
				<form id="mainform" action="">
				<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
				<tr>
					<th class="table-header-check" id="head">No.#</th>
					<th class="table-header-repeat line-left minwidth-1" width="200px"><a href="">Company Name</a></th>
					<th class="table-header-repeat line-left minwidth-1" width="285px"><a href="">Company Address</a></th>
					<th class="table-header-repeat line-left" width="220px"><a href="">Company Email</a></th>
					<th class="table-header-repeat line-left" width="150px"><a href="">Country Name</a></th>
					<th class="table-header-repeat line-left" width="155px;"><a href="">Contact Number</a></th>
					<th class="table-header-options line-left"><a href="">Options</a></th>
				</tr>
				<tr>
				<?php
					if($_SESSION['account_type']=='User'){			
						include("query/view_affiliate_users.php");
					}else{
						include("query/view_affiliate.php"); 
					}
				?>
				</tr>
				</table>
				<!--  end product-table................................... --> 
				</form>
			</div>
			<!--  end content-table  -->
			
			<!--  start paging..................................................... -->
			<table border="0" cellpadding="0" cellspacing="0" id="paging-table">	
			<tr>
			<td>
			<?php
				if($_SESSION['account_type']=='User'){
					if ($page == 0){$page = 1;}
					$prev = $page - 1;	
					$next = $page + 1;							
					$lastpage = ceil($total_pages/$limit);		
					$LastPagem1 = $lastpage - 1;
		
					$paginate = '';
					if($lastpage > 1)
					{	
						$paginate .= "<div class='paginate'>";
						// Previous
						if ($page > 1){
							$paginate.= "<a href='panel.php?page=affiliate&idx=$prev'>previous</a>";
						}else{
							$paginate.= "<span class='disabled'>previous</span>";	}
						// Pages	
						if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
						{	
							for ($counter = 1; $counter <= $lastpage; $counter++)
							{
								if ($counter == $page){
									$paginate.= "<span class='current'>$counter</span>";
								}else{
									$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
							}
						}
						elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
						{
							// Beginning only hide later pages
							if($page < 1 + ($stages * 2))		
							{
								for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$lastpage'>$lastpage</a>";		
							}
							// Middle hide some front and some back
							elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
							{
								$paginate.= "<a href='panel.php?page=affiliate&idx=1'>1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$lastpage'>$lastpage</a>";		
							}
							// End only hide early pages
							else
							{
								$paginate.= "<a href='panel.php?page=affiliate&idx=1'>1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
							}
						}
									
								// Next
						if ($page < $counter - 1){ 
							$paginate.= "<a href='panel.php?page=affiliate&idx=$next'>next</a>";
						}else{
							$paginate.= "<span class='disabled'>next</span>";
						}
							
						$paginate.= "</div>";		
					}
						echo $paginate;
						echo '<div style="margin-left:160px; margin-top:20px;"><strong>'.$total_pages.'&nbsp;Results</strong></div>';
				}else{
					if ($page == 0){$page = 1;}
					$prev = $page - 1;	
					$next = $page + 1;							
					$lastpage = ceil($total_pages/$limit);		
					$LastPagem1 = $lastpage - 1;
		
					$paginate = '';
					if($lastpage > 1)
					{	
						$paginate .= "<div class='paginate'>";
						// Previous
						if ($page > 1){
							$paginate.= "<a href='panel.php?page=affiliate&idx=$prev'>previous</a>";
						}else{
							$paginate.= "<span class='disabled'>previous</span>";	}
						// Pages	
						if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
						{	
							for ($counter = 1; $counter <= $lastpage; $counter++)
							{
								if ($counter == $page){
									$paginate.= "<span class='current'>$counter</span>";
								}else{
									$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
							}
						}
						elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
						{
							// Beginning only hide later pages
							if($page < 1 + ($stages * 2))		
							{
								for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>&idx=$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$lastpage'>$lastpage</a>";		
							}
							// Middle hide some front and some back
							elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
							{
								$paginate.= "<a href='panel.php?page=affiliate&idx=1'>1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
								$paginate.= "...";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$LastPagem1'>$LastPagem1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=$lastpage'>$lastpage</a>";		
							}
							// End only hide early pages
							else
							{
								$paginate.= "<a href='panel.php?page=affiliate&idx=1'>1</a>";
								$paginate.= "<a href='panel.php?page=affiliate&idx=2'>2</a>";
								$paginate.= "...";
								for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
								{
									if ($counter == $page){
										$paginate.= "<span class='current'>$counter</span>";
									}else{
										$paginate.= "<a href='panel.php?page=affiliate&idx=$counter'>$counter</a>";}					
								}
							}
						}
									
								// Next
						if ($page < $counter - 1){ 
							$paginate.= "<a href='panel.php?page=affiliate&idx=$next'>next</a>";
						}else{
							$paginate.= "<span class='disabled'>next</span>";
							}
						
						$paginate.= "</div>";		
						}
						echo $paginate;
						echo '<div style="margin-left:160px; margin-top:20px;"><strong>'.$total_pages.'&nbsp;Results</strong></div>';
						
						
			
				}
			?>
			</td>	
			</tr>
			</table>
			<!--  end paging................ -->
			<div class="clear"></div>
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->

<div class="clear">&nbsp;</div>
